package tsing.javase.quartz;

import com.alibaba.fastjson.JSON;
import org.quartz.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;


//保存在JobDataMap传递的参数
@PersistJobDataAfterExecution
//保证多个任务间不会同时执行
@DisallowConcurrentExecution
public class PrintWordJob  implements Job {

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobKey jobKey = new JobKey("55555");
        try {
//            System.out.println("scheduler:"+jobExecutionContext.getScheduler().getJobDetail(jobKey).getJobDataMap().get("2"));
            System.out.println("jobDetail:"+JSON.toJSONString(jobExecutionContext.getJobDetail()));
            System.out.println("jobDetail 's JobDataMap:"+JSON.toJSONString(jobExecutionContext.getJobDetail().getJobDataMap()));

            System.out.println("trigger:"+jobExecutionContext.getTrigger().getJobDataMap().get("1"));
            System.out.println("trigger:"+jobExecutionContext.getTrigger().getJobDataMap().get("Tsing'job"));

            String printTime = new SimpleDateFormat("yy-MM-dd HH-mm-ss").format(new Date());
            System.out.println("PrintWordsJob start at:" + printTime + ", prints: Hello Job-" + new Random().nextInt(100));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
